home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11938 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mayne.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: RS232 & Strings
  5. Date: 27 Mar 1996 12:34:28 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4jc8okINNahh@mayne.ugrad.cs.ubc.ca>
  8. References: <Pine.SUN.3.91.960326144705.10920A-100000@Ra.MsState.Edu> <315953AB.47C1@airmail.net>
  9. NNTP-Posting-Host: mayne.ugrad.cs.ubc.ca
  10.  
  11. In article <315953AB.47C1@airmail.net>, Mark Nelson  <markn@airmail.net> wrote:
  12. >> I need to be able to receive a string that is ten
  13. >> char. long (starting w/ a + or - and ending with a <CR> ) from an
  14. >> external device that is hooked to a PC RS232 port.  I have gotten the
  15. >> port initialized, etc. can receive some data from it, but I need to be
  16. >> able to receive a string from the device.  Using inport and casting 
  17. >
  18. >You are going to need an interrupt driven routine to receive characters.
  19. >Trying to read them in using polling is not going to work, because
  20. >you are inevitably going to miss some characters.  
  21.  
  22. That is false. Polling is the fastest way to receive characters, at the expense
  23. of everything. You are less likely to miss characters with _continous_ polling
  24. than with interrupts.  The reason modern serial adapters have buffered FIFO
  25. UARTS is precisely for the reason that interrupt service routines just kick in
  26. too slowly to keep up with the bps rate! A CPU-wasting polled loop on the same
  27. hardware could happily ignore the UART, and just pull bytes directly off the
  28. receive register. I've had one programmer tell me that he transferred a file
  29. between two 8088 machines at full 115,200 kbps using polled I/O, a feat you
  30. could not accomplish with an interrupt service routine on the same hardware.
  31.  
  32. Remember, before you leave a polled loop to do something else, you can always
  33. assert a hand-shaking signal to prevent overflow while you are ignoring the
  34. device.
  35.  
  36. There is no faster way to respond to a device than to monitor its
  37. status register with a tight loop and do something as soon as you see the
  38. change you are looking for.
  39.  
  40. Polled IO in a pre-emptive MT system is different, though. When the routine is
  41. pre-empted by the kernel, you have trouble! 
  42. -- 
  43.  
  44.